//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using EntLibContrib.Validation.Configuration.Design.UI;

namespace EntLibContrib.Validation.Configuration.Design
{
	/// <summary>
	/// Test Validator Command
	/// </summary>
	public class TestValidatorCommand : ValidateNodeCommand
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="TestValidatorCommand"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		public TestValidatorCommand(IServiceProvider serviceProvider)
			: base(serviceProvider)
		{
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Executes the validation for the current node and all the child nodes.
		/// </summary>
		/// <param name="node">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ConfigurationNode"/> to validate.</param>
		protected override void ExecuteCore(ConfigurationNode node)
		{
			base.ExecuteCore(node);
			if (this.ValidationSucceeded)
			{
				SingleValidatorNodeBase validator = node as SingleValidatorNodeBase;
				if (validator != null)
				{
					ValidatorData validatorData = validator.CreateValidatorData();
					using (TestValidatorUI validatorTestUI = new TestValidatorUI(validatorData))
					{
						validatorTestUI.ShowDialog();
					}
				}
			}
		}
		#endregion
	}
}
